#
# PREREQUISITES
#
# apt-get install linux-headers-$(uname -r)
# apt-get install build-essential devscripts ubuntu-dev-tools debhelper dh-make diff patch cdbs quilt gnupg fakeroot lintian  pbuilder piuparts
#

ifeq (,$(BUILD_KERNEL))
BUILD_KERNEL=$(shell uname -r)
endif
HERE=$(shell pwd)
PF_RING_HOME=$(HERE)/../../


all: clean pre build

pre:
	-mv *.deb packages
	cat /dev/null > debian/files
	@echo "************************************************************"
	@echo "- REMEMBER to upgrade dependency in debian/control"
	@echo "- REMEMBER to set the kernel version in debian/control"
	@echo "- Make sure you have updated the version in debian/changelog"
	@echo "************************************************************"
	mkdir -p debian/lib debian/usr/include/linux debian/usr/local/bin debian/usr/local/pfring/drivers/DNA
	cd $(PF_RING_HOME)/kernel; make; make install DESTDIR=$(HERE)/debian
	cd $(PF_RING_HOME)/userland; make
	cd $(PF_RING_HOME)/userland/snort/pfring-daq-module; autoreconf -ivf; ./configure; make; mkdir -p $(HERE)/debian/usr/local/lib/daq; cp $(PF_RING_HOME)/userland/snort/pfring-daq-module/.libs/daq_pfring.la $(PF_RING_HOME)/userland/snort/pfring-daq-module/.libs/daq_pfring.so $(HERE)/debian/usr/local/lib/daq
	cd $(PF_RING_HOME)/userland/lib; make install DESTDIR=$(HERE)/debian
	cd $(PF_RING_HOME)/userland/examples; cp pfcount pfsend pfwrite $(HERE)/debian/usr/local/bin
	cd $(PF_RING_HOME)/userland/examples_libzero; cp pfdnacluster_master $(HERE)/debian/usr/local/bin
	cd $(PF_RING_HOME)/drivers/DNA/; make; cp e1000e-2.5.4-DNA/src/e1000e.ko igb-5.0.6-DNA/src/igb.ko ixgbe-3.21.2-DNA/src/ixgbe.ko $(HERE)/debian/usr/local/pfring/drivers/DNA
	@find ./debian -name "*~" -exec /bin/rm {} ';' 

build:
	dpkg-buildpackage -rfakeroot -b -us -uc #-d
	@\rm -f ../pfring_*dsc ../pfring_*.gz ../pfring_*changes 
	@/bin/mv ../pfring_*deb . 
	@echo 
	@echo "Package built." 
	@/bin/ls  pfring_*deb 
	@echo "-------------------------------" 
	-dpkg --contents  pfring_*deb 
	@echo "-------------------------------" 


clean:
	-rm -rf debian/tmp
	-rm -rf debian/usr
	-rm -rf debian/lib
